package edu.nf.vac.auth.service;

import edu.nf.vac.auth.exception.AuthenticateException;
import edu.nf.vac.auth.inf.UserAuthService;
import edu.nf.vac.users.dto.UserDTO;
import edu.nf.vac.users.inf.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Author : QYM
 * @create 2022/3/30
 * 用户认证
 */
@Slf4j
@DubboService(interfaceClass = UserAuthService.class,version = "1.0.0")
public class UserPasswordAuthServiceImpl implements UserAuthService{
    @DubboReference(interfaceClass = UserService.class,version = "1.0.0")
    private UserService service;

    @Override
    public <T> T authenticate(String account, String password) {
        UserDTO userDTO = service.getUserByTel(account);
        if (userDTO == null && !password.equals(userDTO.getUserPassword())){
            throw new AuthenticateException("账号或密码错误");
        }
        return (T)userDTO;
    }
}
